<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('抽检列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="job-form">
                <div class="select-list">
                    <ul>
                        <li>
                            批次号码：<input type="text" name="batchCode"/>
                        </li>
                        <li>
                            批次类型：<input type="text" name="batchType"/>
                        </li>
                        <li>
                            发送状态：<select name="sendStatus" th:with="type=${@dict.getType('batch_send_type')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-responsive">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var detailFlag = '';
    var batchSendFlag = '';
    var batchSendType = [[${@dict.getType('batch_send_type')}]];
    var prefix = ctx + "data/sampling/mot";

    $(function () {
        var options = {
            url: prefix + "/list",
            detailUrl: prefix + "/detail/{id}",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "mot批量发送任务",
            showToggle: false,
            showColumns: false,
            showSearch: false,
            columns: [
                {
                    field: 'batchCode',
                    title: '批次号码'
                },
                {
                    field: 'batchType',
                    title: '批次类型'
                },
                {
                    field: 'nodeId',
                    title: '节点编号'
                },
                {
                    field: 'sendStatus',
                    title: '发送状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(batchSendType, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '发送时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '"href="javascript:void(0)" onclick="detail(\''+ row.batchCode +'\')"><i class="fa fa-search"></i>发送详情</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + batchSendFlag + '" href="javascript:void(0)" onclick="batchSend(\'' + row.batchCode + '\',\''+row.sendStatus+'\')"><i class="fa fa-play-circle-o"></i>批量发送</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    /* 批量发送 */
    function batchSend(batchCode,sendStatus) {
        if ($.common.equals(sendStatus,'2')){
            $.modal.alertWarning("已经批量发送过了,不能重复发送");
            return;
        }
        $.modal.confirm("确认要批量发送吗？", function () {
            $.operate.get(prefix + "/batch/send/"+batchCode);
        })
    }

    /*详细*/
    function detail(batchCode) {
        var url = prefix + '/detail/' + batchCode;
        $.modal.openTab("mot批次发送详情", url);
    }

</script>
</body>
</html>